
using OhioState.AssetManaged;
using OhioState.Graphics;
using OhioState.Graphics.Proxy;



namespace OhioState.Graphics.OpenGL
{
    public class BoxBoundaryHandler : OpenGLObject, IDrawable
    {
        public IMaterial Material
        {
            get { return _boxProxy.Material; }
            set { }
        }
        public IBoundingVolume BoundingVolume
        {
            get { return _boxProxy.BoundingVolume; }
        }

        public int DrawablePosition
        {
            get { return _realBoxBoundary.DrawablePosition; }
            set { _realBoxBoundary.DrawablePosition = value; }
        }
       
        private BoxBoundaryProxy _boxProxy;
        private BoxBoundaryGL _realBoxBoundary;
        public BoxBoundaryHandler(BoxBoundaryProxy proxyObj)
            : base(proxyObj)
        {
            _boxProxy = proxyObj;
            _realBoxBoundary = new BoxBoundaryGL(_boxProxy.BoundingVolume as BoundingBox);
        }
        public void Render(IRenderPanel panel)
        {
            Update(panel);
            _realBoxBoundary.Render(panel);
        }

        public override void Update(IRenderPanel panel)
        {
            if (this.Invalid)
            {
                this.Invalid = false;
                _realBoxBoundary.DrawBackFaces = _boxProxy.DrawBackFaces;
                _realBoxBoundary.DrawFrontFaces = _boxProxy.DrawFrontFaces;
                _realBoxBoundary.BoundingVolume = _boxProxy.BoundingVolume;
                _realBoxBoundary.Material = panel.ResourceManager.GetItem(_boxProxy.Material as IAssetManaged) as IMaterial;
            }
        }
    }
}
